package com.liu.config;

import at.pollux.thymeleaf.shiro.dialect.ShiroDialect;
import org.apache.shiro.realm.Realm;
import org.apache.shiro.realm.text.TextConfigurationRealm;
import org.apache.shiro.spring.web.config.DefaultShiroFilterChainDefinition;
import org.apache.shiro.spring.web.config.ShiroFilterChainDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: 刘浩然
 * @Date: 2020/3/24 17:47
 */
@Configuration
public class ShiroConfig {
@Bean
public Realm realm(){ //realm 的中文意思为 "领域"
    TextConfigurationRealm realm =new TextConfigurationRealm();
    realm.setUserDefinitions("sang=123,user\n admin=123,admin");//定义用户，密码，及角色
    realm.setRoleDefinitions("admin=read,write\n user=read");//定义角色以及角色的权限
    return  realm;
}
@Bean
public ShiroFilterChainDefinition shiroFilterChainDefinition(){
    DefaultShiroFilterChainDefinition chainDefinition=new DefaultShiroFilterChainDefinition();//过滤器链条
    chainDefinition.addPathDefinition("/login","anon");
    chainDefinition.addPathDefinition("/doLogin","anon");
    chainDefinition.addPathDefinition("/logout","logout");
    chainDefinition.addPathDefinition("/**","authc");
    return chainDefinition;
}
@Bean
public ShiroDialect shiroDialect(){
    return new ShiroDialect();
}






}
